version: 0.1

# Phases are collection of commands that get executed on Device Farm.
phases:
  # The install phase includes commands that install dependencies that your tests use.
  # Default dependencies for testing frameworks supported on Device Farm are already installed.
  install:
    commands:

  # The pre-test phase includes commands that setup your test environment.
  pre_test:
    commands:
      # Print this so that the upload script can read and process the benchmark config
      - echo "The benchmark config is {{ benchmark_config_id }}"

      # Download the model from S3
      - curl -s --fail '{{ model_path }}' -o model.zip
      - unzip model.zip && ls -la

      # Extract the app
      - unzip $DEVICEFARM_APP_PATH -d /tmp

      # Copy the model
      - mkdir -p /tmp/Payload/Benchmark.app/aatp/data
      - cp tokenizer.* /tmp/Payload/Benchmark.app/aatp/data
      - cp *.pte /tmp/Payload/Benchmark.app/aatp/data
      - ls -all /tmp/Payload/Benchmark.app/aatp/data

      - mkdir $DEVICEFARM_TEST_PACKAGE_PATH/Debug-iphoneos
      - mkdir $DEVICEFARM_TEST_PACKAGE_PATH/Release-iphoneos
      - cp -r /tmp/Payload/Benchmark.app $DEVICEFARM_TEST_PACKAGE_PATH/Debug-iphoneos/
      - cp -r /tmp/Payload/Benchmark.app $DEVICEFARM_TEST_PACKAGE_PATH/Release-iphoneos/

  # The test phase includes commands that run your test suite execution.
  test:
    commands:
      # Fail the test if the model doesn't exist, doing it here so that AWS can report the status back
      - echo "Verify model"
      - curl -I --fail '{{ model_path }}' || false

      # Run the benchmark
      - xcodebuild test-without-building -destination id=$DEVICEFARM_DEVICE_UDID -xctestrun $DEVICEFARM_TEST_PACKAGE_PATH/*.xctestrun -derivedDataPath $DEVICEFARM_LOG_DIR

  # The post test phase includes are commands that are run after your tests are executed.
  post_test:
    commands:

# The artifacts phase lets you specify the location where your tests logs, device logs will be stored.
# And also let you specify the location of your test logs and artifacts which you want to be collected by Device Farm.
# These logs and artifacts will be available through ListArtifacts API in Device Farm.
artifacts:
  # By default, Device Farm will collect your artifacts from following directories
  - $DEVICEFARM_LOG_DIR
